<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2019/6/13
 * Time: 15:26
 */
namespace Modules\Admin\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Models\System;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class SystemController extends Controller{
    //积分系统显示隐藏
    public function scoreOpenApi(Request $request){
        try{
            $open = $request->input("open");
            $system = System::find(1);
            $system->open = $open;
            $system->save();
            return self::success();
        }catch (\Exception $e){
            Log::error($e);
            return self::error(500);
        }
    }

    //其他设置
    public function otherSetApi(Request $request){
        try{
            $score_ratio = $request->input("score_ratio",false);
            $sell_ratio = $request->input("sell_ratio",false);
            $invit_ratio = $request->input("invit_ratio",false);
            if (!$score_ratio || !$sell_ratio || !$invit_ratio)return self::error(1000);
            if ($sell_ratio>1)return self::error(1031);
            $system = System::find(1);
            $system->score_ratio = $score_ratio;
            $system->sell_ratio = $sell_ratio;
            $system->invit_ratio = $invit_ratio;
            $system->save();
            return self::success();
        }catch (\Exception $e){
            Log::error($e);
            return self::error(500);
        }
    }
}